<template>
    <h1>用户投资赎回</h1>

    <table>
        <tr>
            <td>投资项目名称</td>
            <td>{{ Info.I_Name }}</td>
        </tr>

        <tr>
            <td>项目总金额</td>
            <td>{{ Info.I_Budget }}</td>
        </tr>

        <tr>
            <td>用户投资金额</td>
            <td>{{ Info.UT_Money }}</td>
        </tr>

        <tr>
            <td>赎回金额</td>
            <td>
                <input type="text" v-model="Money" >
            </td>
        </tr>

        <tr>
            <td colspan="2">
                <input type="button" value="确认赎回" @click="AddUserInvestRedeemInfo" >
            </td>
        </tr>

    </table>


</template>

<script setup lang="ts">
import { ref,onMounted } from 'vue';
import axios from 'axios';
import { useRouter,useRoute } from 'vue-router';

const Info = ref({
    UT_Id:'',
    UT_Money:'',
    I_Name:'',
    I_Budget:''
})

const Money = ref('');

const router = useRouter();

const route = useRoute();

console.log(route.params.Id);

onMounted(()=>{
    SearShowUserInvest();
})

const SearShowUserInvest = ()=>{
    axios({
        method:'get',
        url:'http://localhost:56707/api/Invest/SearShowUserInvest',
        params:{
            Id:route.params.Id
        }
    })
    .then(res=>{
        console.log(res);
        Info.value = res.data[0];
    })
    .catch(err=>{
        console.log(err);
    })
}

const AddUserInvestRedeemInfo = ()=>{
    axios({
        method:'post',
        url:'http://localhost:56707/api/Invest/AddUserInvestRedeemInfo',
        data:{
            UT_Id:route.params.Id,
            UIR_Money:Money.value
        }
    })
    .then(res=>{
        if(res.data>0){
            alert('用户投资赎回成功');
            router.push('/UserRedeemShow')
        }
        else{
            alert('用户投资赎回失败');
            return;
        }
    })
    .catch(err=>{
        console.log(err);
    })
}

</script>
